﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NWBA_Public
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // At login page.
            if(Request.QueryString["logout"] != null)
            {
                Session.Clear();
                Response.Redirect("Login.aspx", true);
            }

            NWBA_Public.Site master = Master as NWBA_Public.Site;
            master.NavBar.Visible = false;
        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            Customer customer = LoginBusinessObject.LoginUser(UsernameTextBox.Text, PasswordTextBox.Text);

            if(customer != null)
            {
                if (customer.CustomerID == 1)
                {
                    Session["Role"] = "Admin";
                }
                Session["Username"] = UsernameTextBox.Text;
                Session["ID"] = customer.CustomerID;
                Session["Customer"] = customer;
                Response.Redirect("ATM.aspx", true);
            }
            else
            {
                ErrorLabel.Visible = true;
            }
        }
    }
}
